package com.sgb.kjwl.view.ui.fragment.machine;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentAskLeasePickBinding;
import com.sgb.kjwl.di.machine.DaggerMachineFragComponent;
import com.sgb.kjwl.di.machine.MachineFragModule;
import com.sgb.jicai.entity.CentralizedMiningEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.jicai.entity.JiCaiHomeListRequestBean;
import com.sgb.kjwl.model.entity.lease.AskLeaseItemEntity;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.jicai.view.adapter.CentralizedMiningCuttingLineAdapter;
import com.sgb.kjwl.view.widget.DictWindow5;
import com.sgb.kjwl.view.widget.ThreeLevelAreaWindow;
import com.sgb.kjwl.viewmodel.machine.AskLeasePickFragmentModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.entity.BaseAreaEntity;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.view.selection.CommonPopEntity;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 集采租赁
 */
public class AskLeasePickFragment extends AppLazyFragment {

    private FragmentAskLeasePickBinding binding;
    //适配器
    private CentralizedMiningCuttingLineAdapter centralizedMiningAdapter;

    private String classNo = "";
    private String typeNo = "";
    private String sortNo = "";
    private String stateNo = "";
    private String provinceNo = "";
    private String cityNo = "";
    private String provinceName = "";
    private String cityName = "";
    private String districtNo = "";

    private DictWindow5 sortPopWindow;
    private DictWindow5 statePopWindow;
    private ThreeLevelAreaWindow mAddressPop;
    private String categoryType = "";
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;//省市区
    private List<AskLeaseItemEntity<List<AskLeaseItemEntity>>> allDatas;
    private List<PickSelectEntity> classDatas;
    private List<PickSelectEntity> typeDatas;
    private List<DictEntity3> sortDatas, stateDatas;
    private JiCaiHomeListRequestBean requestBean = new JiCaiHomeListRequestBean();
    @Inject
    AskLeasePickFragmentModel model;
    private boolean isFilter = true;

    public static AskLeasePickFragment newInstance(String type, ArrayList<AskLeaseItemEntity<List<AskLeaseItemEntity>>> list, boolean isFilter) {
        AskLeasePickFragment fragment = new AskLeasePickFragment();
        Bundle bundle = new Bundle();
        bundle.putString("type", type);
        bundle.putSerializable("data", list);
        bundle.putBoolean("isFilter", isFilter);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerMachineFragComponent.builder().appComponent(appComponent).machineFragModule(new MachineFragModule(this)).build().inject(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_ask_lease_pick, container, false);
        return binding.getRoot();
    }

    @Override
    protected void onLazyLoad() {
        if (getArguments() != null) {
            categoryType = getArguments().getString("type");
            isFilter = getArguments().getBoolean("isFilter", true);
        }

        if (!TextUtils.isEmpty(categoryType)) {
            allDatas = (ArrayList<AskLeaseItemEntity<List<AskLeaseItemEntity>>>) getArguments().getSerializable("data");
        } else {
            allDatas = new ArrayList<>();
            binding.tabLayout.setVisibility(View.GONE);
            binding.typeLayout.setVisibility(View.GONE);
        }
        if (!isFilter) {
            binding.roomLayout.setVisibility(View.GONE);
            binding.tabType.setVisibility(View.GONE);
            binding.recyclerView.setLoadingMoreEnabled(false);
        }
        initData();

    }

    //initView()执行在onLazyLoad之前
    @Override
    protected void initView() {
        initTabType();
//        binding.classifyLayout.setOnClickListener(this);
//        binding.typeLayout.setOnClickListener(this);
        binding.areaLayout.setOnClickListener(this);
        binding.sortLayout.setOnClickListener(this);
        binding.stateLayout.setOnClickListener(this);

        if (centralizedMiningAdapter == null) {
            centralizedMiningAdapter = new CentralizedMiningCuttingLineAdapter(getActivity(), null);
        }
        centralizedMiningAdapter.setOnItemClick(new AdapterOnItemClick<CentralizedMiningEntity>() {
            @Override
            public void onItemClick(CentralizedMiningEntity centralizedMiningEntity, int position) {
                if (!ClickUtils.isDoubleClick()) {
                    model.getH5Url(centralizedMiningEntity.getNo());
                }
            }
        });
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        //解决数据加载不完的问题
        binding.recyclerView.setHasFixedSize(true);
        //解决数据加载完成后, 没有停留在顶部的问题
        binding.recyclerView.setFocusable(false);
        binding.recyclerView.setAdapter(centralizedMiningAdapter);
        binding.recyclerView.setLoadingMoreEnabled(true);
        binding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                initFilterData(false);
            }

            @Override
            public void onLoadMore() {
                initFilterData(true);
            }
        });

//        classPopWindow = new LeaseAskMapPopWindow(getActivity());
//        classPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
//            @Override
//            public void result(Object key1, Object key2, Object key3) {
//                updateChooseTextStatus(binding.classifyLayout, binding.tvClassify, 2, ((PickSelectEntity) key1).getPickerViewText());
//                classNo = ((PickSelectEntity) key1).getNo();
//                if (TextUtils.isEmpty(classNo)) {
//                    typeDatas.clear();
//                    PickSelectEntity entity = new PickSelectEntity();
//                    entity.setNo("");
//                    entity.setProjectscale("不限");
//                    typeDatas.add(0, entity);
//                    typePopWindow.goodsTypeAdapter.setDefItem(0);
//                } else {
//                    int classIndex = (int) key2;
//                    typeDatas.clear();
//                    if ("2".equals(categoryType)) {
//                        typeDatas.addAll(getCarByTypeData());
//                    } else {
//                        for (AskLeaseItemEntity<List<AskLeaseItemEntity>> ll : allDatas.get(classIndex - 1).getChildren()) {
//                            PickSelectEntity child = new PickSelectEntity();
//                            child.setNo(ll.getNo());
//                            child.setProjectscale(ll.getName());
//                            typeDatas.add(child);
//                        }
//                    }
//
//                    PickSelectEntity entity = new PickSelectEntity();
//                    entity.setNo("");
//                    entity.setProjectscale("不限");
//                    typeDatas.add(0, entity);
//                    typePopWindow.goodsTypeAdapter.setDefItem(0);
//                }
//
//                typeNo = "";//选择分类时,将原先的子类型清空
//                initFilterData(false);
//            }
//        });
//        classPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                if ("分类".equals(binding.tvClassify.getText()) || "车型".equals(binding.tvClassify.getText())) {
//                    updateChooseTextStatus(binding.classifyLayout, binding.tvClassify, 0, null);
//                } else {
//                    updateChooseTextStatus(binding.classifyLayout, binding.tvClassify, 2, null);
//                }
//            }
//        });
//
//        typePopWindow = new LeaseAskMapPopWindow(getActivity());
//        typePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
//            @Override
//            public void result(Object key1, Object key2, Object key3) {
//                updateChooseTextStatus(binding.typeLayout, binding.tvType, 2, ((PickSelectEntity) key1).getPickerViewText());
//                typeNo = ((PickSelectEntity) key1).getNo();
//                requestBean.setTypeNo(classNo);//最后一级类型
//                initFilterData(false);
//            }
//        });
//        typePopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                if ("类型".equals(binding.tvType.getText()) || "品牌".equals(binding.tvType.getText())) {
//                    updateChooseTextStatus(binding.typeLayout, binding.tvType, 0, null);
//                } else {
//                    updateChooseTextStatus(binding.typeLayout, binding.tvType, 2, null);
//                }
//            }
//        });

        mAddressPop = new ThreeLevelAreaWindow(getActivity());
        mAddressPop.setBgView(binding.grayLayout);
        mAddressPop.setMemberHeight();
        mAddressPop.setProvinceSingle();
        mAddressPop.setCitySingle();
        mAddressPop.setAreaSingle();
        mAddressPop.setShowSimpleName(true);
        mAddressPop.setOnResultClick((key1, key2, key3) -> {
            try {
                List<BaseAreaEntity> listKey1 = (List<BaseAreaEntity>) key1;
                List<BaseAreaEntity> listKey2 = (List<BaseAreaEntity>) key2;
                List<BaseAreaEntity> listKey3 = (List<BaseAreaEntity>) key3;
                districtNo = "";
                if (listKey3 != null && listKey3.size() > 0) {
                    districtNo = listKey3.get(0).getNo();
                }
                if (listKey2 != null && listKey2.size() > 0) {
                    cityNo = listKey2.get(0).getNo();
                    cityName = listKey2.get(0).getName();
                } else {
                    cityNo = "";
                }

                provinceNo = listKey1.get(listKey1.size() - 1).getNo();
                provinceName = listKey1.get(listKey1.size() - 1).getName();
                requestBean.setProvinceNo(provinceNo);
                requestBean.setCityNo(cityNo);
                requestBean.setDistrictNo(districtNo);
            } catch (Exception exception) {
            }

            initFilterData(false);
            if (!TextUtils.isEmpty(cityName) && "不限".equals(cityName)) {
                updateChooseTextStatus(binding.areaLayout, binding.tvArea, 2, cityName);
            } else {
                updateChooseTextStatus(binding.areaLayout, binding.tvArea, 2, provinceName);
            }

        });
        mAddressPop.setOnDismissListener(() -> {
            updateChooseTextStatus(binding.areaLayout, binding.tvArea, "集采范围".equals(binding.tvArea.getText()) ? 0 : 2, null);
        });

        sortPopWindow = new DictWindow5(getActivity());
        sortPopWindow.setOnCallBack(new DictWindow5.OnCallBack() {
            @Override
            public void result(DictEntity3 dictEntity) {
                updateChooseTextStatus(binding.sortLayout, binding.tvSort, 2, dictEntity.getName());
                sortNo = dictEntity.getId();
                initFilterData(false);
            }
        });
        sortPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                updateChooseTextStatus(binding.sortLayout, binding.tvSort, "集采方式".equals(binding.tvSort.getText()) ? 0 : 2, null);
            }
        });

        statePopWindow = new DictWindow5(getActivity());
        statePopWindow.setOnCallBack(new DictWindow5.OnCallBack() {
            @Override
            public void result(DictEntity3 dictEntity) {
                updateChooseTextStatus(binding.stateLayout, binding.tvState, 2, dictEntity.getName());
                stateNo = dictEntity.getId();
                requestBean.setStatus(stateNo);
                initFilterData(false);
            }
        });
        statePopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                updateChooseTextStatus(binding.stateLayout, binding.tvState, "集采状态".equals(binding.tvState.getText()) ? 0 : 2, null);
            }
        });

    }

    private void initTabType() {
        //机械列表分类标题
        binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        binding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                updateChooseTextStatus(binding.typeLayout, binding.tvType, 0, "类型");
                classNo = classDatas.get(tab.getPosition()).getNo();
                if (TextUtils.isEmpty(classNo)) {
                    typeDatas.clear();
                    PickSelectEntity entity = new PickSelectEntity();
                    entity.setNo("");
                    entity.setProjectscale("不限");
                    typeDatas.add(0, entity);
//                    typePopWindow.goodsTypeAdapter.setDefItem(0);
                } else {
                    int classIndex = tab.getPosition();
                    typeDatas.clear();
                    if ("2".equals(categoryType)) {
                        typeDatas.addAll(getCarByTypeData());
                    } else {
                        for (AskLeaseItemEntity ll : allDatas.get(classIndex - 1).getChildren()) {
                            PickSelectEntity child = new PickSelectEntity();
                            child.setNo(ll.getNo());
                            child.setProjectscale(ll.getName());
                            typeDatas.add(child);
                        }
                    }

                    PickSelectEntity entity = new PickSelectEntity();
                    entity.setNo("");
                    entity.setProjectscale("不限");
                    typeDatas.add(0, entity);
//                    typePopWindow.goodsTypeAdapter.setDefItem(0);
                }

//                isLoadMore = false;
//                page = 1;
                typeNo = "";
                initFilterData(false);
                showTypeTab();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });


        binding.tabType.setTabMode(TabLayout.MODE_SCROLLABLE);
        binding.tabType.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                checkDismiss(0);
                typeNo = typeDatas.get(tab.getPosition()).getNo();
                initFilterData(false);
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void initData() {
        if ("2".equals(categoryType)) {
            binding.tvClassify.setText("车型");
            binding.tvType.setText("品牌");
        }
        provinceNo = model.getAreaCodeModel();//默认省参数
        requestBean.setProvinceNo(provinceNo);
        classDatas = new ArrayList<>();
        typeDatas = new ArrayList<>();
        showSortData();
        showClassPop();
        initFilterData(false);
        model.groupBuyClassList();
    }

    //因接口返回Json格式不规范,需要在此特别处理一级数据车型
    private void onResetCarByClassData() {
        classDatas.clear();
        for (AskLeaseItemEntity itemEntity : allDatas.get(0).getChildren()) {
            PickSelectEntity selectEntity = new PickSelectEntity();
            selectEntity.setNo(itemEntity.getNo());
            selectEntity.setProjectscale(itemEntity.getName());
            classDatas.add(selectEntity);
        }
    }

    //因接口返回Json格式不规范,转换二级数据品牌
    private List<PickSelectEntity> getCarByTypeData() {
        List<PickSelectEntity> tempData = new ArrayList<>();
        for (AskLeaseItemEntity itemEntity : allDatas.get(1).getChildren()) {
            PickSelectEntity selectEntity = new PickSelectEntity();
            selectEntity.setNo(itemEntity.getNo());
            selectEntity.setProjectscale(itemEntity.getName());
            tempData.add(selectEntity);
        }
        return tempData;
    }


    //列表数据请求
    private void initFilterData(boolean isLoadMore) {
        if (TextUtils.isEmpty(categoryType)) {//全部
            requestBean.setGroupbuyClass("999");//一级类型
        } else if ("0".equals(categoryType)) {//机械
            requestBean.setGroupbuyClass("2");
        } else if ("1".equals(categoryType)) {//设备
            requestBean.setGroupbuyClass("3");
        }
        requestBean.setTypeNo(classNo);
        if (!TextUtils.isEmpty(typeNo)) {
            requestBean.setTypeNo(typeNo);
        }
//        requestBean.setSecondNo(typeNo);
        requestBean.setGroupBuyMode("1");//需方发起
        requestBean.setStatus(stateNo);//集采状态
        requestBean.setGroupBuyType(sortNo);//集采方式
        model.getJiCaiList(requestBean, isLoadMore);
    }

    /**
     * 列表返回数据
     *
     * @param list
     * @param isLoadMore
     */
    public void setJiCaiList(List<CentralizedMiningEntity> list, boolean isLoadMore) {
        if (isLoadMore) {
            binding.recyclerView.loadMoreComplete();
            if (list != null && list.size() > 0) {
                centralizedMiningAdapter.addDatas(list);
            } else {
                binding.recyclerView.setNoMore(true);
            }
        } else {
            binding.recyclerView.refreshComplete();
            if (list != null && list.size() > 0) {
                binding.emptyView.setVisibility(View.GONE);
                binding.recyclerView.setVisibility(View.VISIBLE);
                centralizedMiningAdapter.setDatas(list);
                binding.recyclerView.setNoMore(false);
            } else {
                centralizedMiningAdapter.clearDatas();
                binding.emptyView.setVisibility(View.VISIBLE);
                binding.recyclerView.setVisibility(View.GONE);
            }
        }
    }


    /**
     * @param v
     */
    @Override
    public void onClick(View v) {
        checkDismiss(v.getId());
        switch (v.getId()) {
//            case R.id.classify_layout:
//                if (null != classDatas && classDatas.size() > 0) {
//                    if ("分类".equals(binding.tvClassify.getText()) || "车型".equals(binding.tvClassify.getText())) {
//                        updateChooseTextStatus(binding.classifyLayout, binding.tvClassify, -1, null);
//                    } else {
//                        updateChooseTextStatus(binding.classifyLayout, binding.tvClassify, 1, null);
//                    }
//                    classPopWindow.showPopwindow(binding.classifyLayout);
//                }
//                break;
//            case R.id.type_layout:
//                if (null != typeDatas && typeDatas.size() > 0) {
//                    showTypePop();
//                }
//                break;
            case R.id.area_layout:
                updateChooseTextStatus(binding.areaLayout, binding.tvArea, "集采范围".equals(binding.tvArea.getText()) ? -1 : 1, null);
                mAddressPop.showPopwindow(binding.areaLayout);
                if (null == addressEntityList || addressEntityList.size() == 0) {
                    model.getCityData();
                }
                break;
            case R.id.sort_layout://集采方式
                if (null != sortDatas && sortDatas.size() > 0) {
                    updateChooseTextStatus(binding.sortLayout, binding.tvSort, "集采方式".equals(binding.tvSort.getText()) ? -1 : 1, null);
                    sortPopWindow.setCheckDefaultById(sortNo);
                    sortPopWindow.showPopwindow(binding.sortLayout);
                }
                break;
            case R.id.state_layout://集采方式
                if (null != stateDatas && stateDatas.size() > 0) {
                    updateChooseTextStatus(binding.stateLayout, binding.tvState, "集采状态".equals(binding.tvState.getText()) ? -1 : 1, null);
                    statePopWindow.setCheckDefaultById(stateNo);
                    statePopWindow.showPopwindow(binding.stateLayout);
                }
                break;
            default:
                break;
        }
    }

    private void showClassPop() {
        if ("2".equals(categoryType)) {//车辆求租
            onResetCarByClassData();
        } else {
            for (AskLeaseItemEntity<List<AskLeaseItemEntity>> l : allDatas) {
                PickSelectEntity entity = new PickSelectEntity();
                entity.setNo(l.getNo());
                entity.setProjectscale(l.getName());
                classDatas.add(entity);
            }
        }

        if ("5".equals(categoryType)) {
            binding.typeLayout.setVisibility(View.GONE);
        }

        PickSelectEntity entity = new PickSelectEntity();
        entity.setNo("");
        entity.setProjectscale("全部");
        classDatas.add(0, entity);
//        classPopWindow.setData(classDatas);
//        classPopWindow.goodsTypeAdapter.setDefItem(0);

        for (int i = 0; i < classDatas.size(); i++) {
            binding.tabLayout.addTab(binding.tabLayout.newTab().setText(classDatas.get(i).getProjectscale()));
        }
        binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0));
    }

//    private void showTypePop() {
//        if ("类型".equals(binding.tvType.getText()) || "品牌".equals(binding.tvType.getText())) {
//            updateChooseTextStatus(binding.typeLayout, binding.tvType, -1, null);
//        } else {
//            updateChooseTextStatus(binding.typeLayout, binding.tvType, 1, null);
//        }
//        typePopWindow.showPopwindow(binding.typeLayout);
//        typePopWindow.setData(typeDatas);
//
//    }

    private void showTypeTab() {
        if (typeDatas == null || typeDatas.size() == 0) {
            binding.tabType.setVisibility(View.GONE);
            binding.viewTypeTabLine.setVisibility(View.GONE);
            return;
        }

        //设置类型tab
        if ("不限".equals(typeDatas.get(0).getProjectscale().trim())) {
            typeDatas.get(0).setProjectscale("全部");
            if (typeDatas.size() == 1) {
                binding.tabType.setVisibility(View.GONE);
                binding.viewTypeTabLine.setVisibility(View.GONE);
                return;
            } else {
                binding.tabType.setVisibility(View.VISIBLE);
                binding.viewTypeTabLine.setVisibility(View.VISIBLE);
            }
        }

        binding.tabType.removeAllTabs();
        for (int i = 0; i < typeDatas.size(); i++) {
            binding.tabType.addTab(binding.tabType.newTab().setText(typeDatas.get(i).getProjectscale()));
        }
        binding.tabType.selectTab(binding.tabType.getTabAt(0));
    }

    //集采方式
    private void showSortData() {
        sortDatas = new ArrayList<>();
        sortDatas.add(new DictEntity3("", "全部"));
        sortDatas.add(new DictEntity3("1", "即报即采"));
        sortDatas.add(new DictEntity3("2", "汇集采购"));
        sortPopWindow.setData(sortDatas);
        sortPopWindow.setCheckDefaultById("");
    }

    //集采状态
    public void showStateData(List<CommonPopEntity> entityList) {
        stateDatas = new ArrayList<>();
        for (CommonPopEntity entity : entityList) {
            DictEntity3 dictEntity3 = new DictEntity3();
            dictEntity3.setId(entity.getNo());
            dictEntity3.setName(entity.getPickerViewText());
            stateDatas.add(dictEntity3);
        }
        statePopWindow.setData(stateDatas);
        statePopWindow.setCheckDefaultById("");
    }

    /**
     * 省市区数据信息
     *
     * @param data
     */
    public void showAddressDatas(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data, String provinceNo) {
        this.addressEntityList = data;
        if (data != null && data.size() > 0) {
            this.provinceNo = provinceNo;
            mAddressPop.setData(data, true, provinceNo);
        }
    }

    private void checkDismiss(int resId) {
        if (mAddressPop != null && mAddressPop.isShowing() && R.id.area_layout != resId) {
            mAddressPop.dismiss();
        }
    }


    //更新选项颜色
    private void updateChooseTextStatus(View view, TextView textView, int value, String name) {
        if (value == 0) {
            setTextViewBg(view, textView, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333);
        } else if (value == -1) {
            setTextViewBg(view, textView, R.drawable.search_bg, R.mipmap.ic_up_arrow_n, R.color.color_333333);
        } else if (value == 1) {
            setTextViewBg(view, textView, R.drawable.search_new_blue_bg, R.mipmap.icon_up_red, R.color.color_main);
        } else if (value == 2) {
            setTextViewBg(view, textView, R.drawable.search_new_blue_bg, R.mipmap.icon_down_red, R.color.color_main);
        }
        if (TextUtils.isEmpty(name)) return;
        textView.setText(name);
    }

    //设置背景色和图标
    private void setTextViewBg(View view, TextView textView, int bg, int img, int textColor) {
        view.setBackgroundResource(bg);
        Drawable drawable_n = getResources().getDrawable(img);
        drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());
        textView.setCompoundDrawables(null, null, drawable_n, null);
        textView.setTextColor(getResources().getColor(textColor));
    }

    //提供给外部调用
    public void onLoadMore() {
        initFilterData(true);
    }
}
